package com.fywsy.fyweb.strategy;

import com.fywsy.fyweb.entity.SendItem;
import com.fywsy.fyweb.utils.RestTemplateUtil;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

/**
 * 传奇-红荒大陆
 *
 * 游戏后台实现类
 * 注解gameId对应数据库游戏id
 * 注解GongnengMethod对应数据库功能id
 */
@Component
@GameId(65)
public class CqDaocaorenGameStrategy extends BaseGameStrategy {

    public static final String URL0 = "http://43.159.53.8:5002/api/promotion-code-0";
    public static final String URL10 = "http://43.159.53.8:5002/api/promotion-code-10";

    public static final String PAY = "http://43.159.53.8:99/gmhtss/user/gmquery.php";

    /**
     * type: charge1
     * checknum: diyao88
     * uid: 风云精品
     * num: 19999
     * qu: 1
     *
     * @param item
     * @return
     */
    @GongnengMethod(6501)
    public String cdk(SendItem item) {
        if("1".equals(item.itemId)) {
            return "成功:白嫖码为:" + RestTemplateUtil.sendGetAndGetJsonKey(URL0,"code");
        }
        return "成功:赞助码为:" + RestTemplateUtil.sendGetAndGetJsonKey(URL10,"code");
    }

    /**
     * type: charge1
     * checknum: diyao88
     * uid: 井烨华
     * num: 333444
     * qu: 1
     *
     * @param item
     * @return
     */
    @GongnengMethod(6502)
    public String pay(SendItem item) {
        MultiValueMap<String,String> params = new LinkedMultiValueMap<>();
        params.add("checknum", "diyao88");
        params.add("type", "charge1");
        params.add("qu", "1");

        params.add("uid", item.uid);
        params.add("num", item.number);

        return RestTemplateUtil.sendPostFormAndGetJsonKey(PAY, params,"info");
    }



    @GongnengMethod(9)
    public String clear(SendItem item) {
        System.out.println("清除成功");
        return "清除成功";
    }

    public static void main(String[] args) {
        SendItem item = new SendItem();
        item.uid = "井烨华";
        item.number = "999999";
        item.itemId = "1";
        System.out.println(new CqDaocaorenGameStrategy().pay(item));
    }
}

